package com.kb.controller.icHub;

import com.alibaba.fastjson.JSONObject;
import com.kb.common.MeException;
import com.kb.common.ValidableList;
import com.kb.dto.HubCreateQuote;
import com.kb.service.HubService;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/hub")
public class HubController {

    @Resource
    private HubService hubService;


    @GetMapping("/getHubToken")
    @ResponseBody
    public String getHubToken() throws MeException {
        return hubService.getHubToken();
    }

    //供货查询
    @PostMapping("/getHubquote")
    @ResponseBody
    public JSONObject getHubquote(@RequestBody Map<String, Object> map) throws MeException {
        return hubService.getHubquote(map);
    }

    //创建询价
    @PostMapping("/getInquiry")
    @ResponseBody
    public JSONObject getInquiry(@RequestBody @Validated ValidableList<HubCreateQuote> hubCreateQuote) throws MeException {
        JSONObject inquiry = null;
        for (HubCreateQuote createQuote : hubCreateQuote) {
            List<HubCreateQuote> arr = new ArrayList<>();
            arr.add(createQuote);
            inquiry = hubService.getInquiry(arr);
        }
        return inquiry;
    }

    //询价的报价
    @PostMapping("/getQuotation")
    @ResponseBody
    public JSONObject getQuotation(@RequestBody Map<String, Object> map) throws MeException {
        return hubService.getQuotation(map);
    }


}